import cn.ctodb.im.proto.Auth;
import cn.ctodb.im.proto.Message;

import java.util.Scanner;
import java.util.UUID;

/**
 * All rights Reserved, Designed By www.ctodb.cn
 *
 * @version V1.0
 * @author: lichaohn@163.com
 * @date: 2018-11-08 10:53
 * @Copyright: 2018 www.ctodb.cn All rights reserved.
 */
public class SendTestMain extends TestBase {

    public static void main(String[] strings) throws InterruptedException {
        String uid = null;
        _init();
        Scanner scan = new Scanner(System.in);
        String read;
        logger.debug("测试发送文本消息");
        while ((read = scan.nextLine()) != null) {
            try {
                if (read.startsWith("login")) {
                    String[] strs = read.split("[:]");
                    uid = strs[1];
                    login(strs[1], strs[2]);
                    continue;
                }
                Message.TextReq.Builder tb = Message.TextReq.newBuilder();
                Message.BaseInfo.Builder bb = Message.BaseInfo.newBuilder();
                bb.setCc(System.currentTimeMillis());
                bb.setFrom(uid);
                String[] strs = read.split("[:]");
                bb.setTo(strs[0]);
                tb.setContent(strs[1]);
                tb.setBaseInfo(bb);
                Message.TextReq textReq = tb.build();
                client.send(textReq);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        logger.debug("测试结束");
    }

    private static void login(String uid, String token) {
        Auth.AuthReq authReq = Auth.AuthReq.newBuilder().setUid(uid).setToken(token).build();
        client.send(authReq);
    }
}
